package com.sunq.studio.sys.controller;

import com.sunq.studio.sys.domain.TbSysParams;
import com.sunq.studio.sys.service.SysParamService;
import com.sunq.studio.utils.JsonToOtherUtil;
import com.sunq.studio.utils.OtherPojo;
import com.sunq.studio.utils.ResultObjVO;
import com.sunq.studio.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sunq on 2019/7/21.
 */
@RestController
@RequestMapping("/params")
public class ResoucreController {


    @Autowired
    SysParamService sysParamService;

    @RequestMapping("/paramsbyWaln")
    public ResultObjVO getParamsByType(@RequestBody String data){

        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new TbSysParams() );
        TbSysParams sysParams= (TbSysParams)ob.getObj();

        List<TbSysParams>  res =sysParamService.getParamsByType(sysParams.getType());

        Map<String,String> wlanParam=new HashMap<String,String>();
        for(TbSysParams sysParam:res){
            if("ssid".equals(sysParam.getName() ) ){
                wlanParam.put("ssid",sysParam.getValue());
            }else if("password".equals(sysParam.getName() ) ) {
                wlanParam.put("password",sysParam.getValue());
            }
        }

        if(wlanParam.size()>0){
            return ResultUtil.success(wlanParam);
        }else{
            return  ResultUtil.error("500","数据查询失败");
        }


    }


}
